<template>
  <div>
    <img src="@/assets/logo.png" height="120px" width="300px" alt="分布式电商秒杀系统"/>
  </div>
</template>

<script>

export default {
  name: "Header",
  mounted() {
    //配置
    this.$axios.interceptors.request.use(
      (config) => {
        config.headers.common['token'] = window.sessionStorage.getItem("token")
        return config;
      },
      (error) => {
        console.info(error);
        return Promise.reject(error);
      })
    // setInterval(this.refreshToken,1000*60*10); // 10分钟刷新一次token
    setInterval(this.refreshToken, 30000); // 5秒钟刷新一次token
  },
  methods: {
    refreshToken() {
      this.$axios.get('token/refreshToken').then(response => {
        if (response.data.code === 0) {
          window.sessionStorage.setItem("token", response.data.msg);
          this.$message.success('token刷新成功');
        } else {
          this.$message.error('请联系管理员');
        }
      }).catch(error => {
        this.$message.error(error + "-请联系管理员")
      })
    }
  }
}
</script>

<style scoped>

</style>
